package kafka

import (
	"github.com/sirupsen/logrus"
	event2 "go_knowledge/mq/kafka/event"
	consumer2 "go_knowledge/mq/kafka/event/kafka/consumer"
)

type defaultListener struct {
	addr   []string
	logger *logrus.Logger
}

func NewDefaultListener(addr []string) *defaultListener {
	return &defaultListener{addr: addr}
}

func (dl *defaultListener) SetLogger(logger *logrus.Logger) {
	dl.logger = logger
}

func (dl *defaultListener) Listen(queueName, group string, eventHandler event2.Handler) {
	client := consumer2.NewDefaultConsumerClient(dl.addr, queueName, group)
	if nil != dl.logger {
		client.SetLogger(dl.logger)
	}

	client.Handle(eventHandler)
}
